package com.qf.om.servlet;

import com.qf.om.entity.Student;
import com.qf.om.myutils.DataUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/querystudent")
public class QueryStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        //查询学生列表
        List<Student> studentList = DataUtils.queryStudent();
        //将学生信息放在request作用域中，因为request是在请求时才触发，不请求就没有，可以节省空间
        request.setAttribute("stus", studentList);
//        重定向跳转和转发的区别
//        resp.sendRedirect("/querystudent.jsp");
//        转发
        request.getRequestDispatcher("/querystudent.jsp").forward(request, resp);
    }
}
